<?php

function ss() {
    $config = config_item("wxapp");
    print_r($config);
}

function sendSms($mobile, $content, $do_action = "reg") {
    return sendToCrNew($mobile, $content, $do_action);
}

function sendToCrNew($mobile, $content, $do_action = "reg") {

    $flag = 0;
    $msg = "失败";
    $result = [];

    $config_sms = config_item("xiao_sms");

    if ($do_action=="reg"){
        $msg = sprintf("【i卡运】您的会员注册验证码为%s，请于15分钟内正确输入，如非本人操作，请忽略此短信。", $content);
    }else{
        $msg = sprintf("【i卡运】您修改资料的手机验证码为%s，请于15分钟内正确输入，如非本人操作，请忽略此短信。", $content);
    }
    //$msg = iconv("UTF-8", "gbk//TRANSLIT", $msg);

    $data = array(
        "uid" => $config_sms["qiye_uid"],
        "auth" => $config_sms["auth"],
        "expid" => 0,
        "encode" => "utf-8",
        'mobile' => $mobile, //必填参数。手机号码。多个以英文逗号隔开
        'msg' => urlencode($msg), //必填参数。发送内容（1-500 个汉字）UTF-8编码
    );

    $url = $config_sms["url"]; //提交的url地址

    $str = "";
    foreach ($data as $k => $v) {
        $str .= $k . "=" . $v . "&";
    }
    $str = trim($str, "&");

    $result_str = file_get_contents($url . "?" . $str);

    if ($result_str) {
        $result = explode(",", $result_str);
        if (isset($result[0])) {
            if ($result[0] == "0") {
                $flag = 1;
                $msg = "已发送";
            }
        }
    }
    return [
        "flag" => $flag,
        "msg" => $msg,
        "curl_content" => [
            "url" => $url,
            "params" => $data,
            "results" => $result,
        ]
    ];
}
